import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/views/Layout'
// import '@/router/permission'
// 路由懒加载中
const _import = function(file) {
  return resolve => {
    require(['@/views/' + file + '.vue'], resolve)
  }
}
Vue.use(Router)

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roless)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if fasle ,the page will no be cached(default is false)
  }
**/

/** 初始化时挂载的路由表,不需要超管权限 **/
export const constantRouterMap = [
  {
    path: '/login',
    name: 'login',
    hidden: true,
    component: _import('login/index')
  },
  {
    path: '/404',
    name: '404-view',
    component: _import('errorView/404/index'),
    hidden: true
  },
  {
    path: '/401',
    name: '401-view',
    component: _import('errorView/401/index'),
    hidden: true
  },
  // 空路径默认跳首页
  {
    path: '/',
    redirect: '/dashboard/index'
  },
  {
    path: '/dashboard',
    name: 'dashboard',
    component: Layout,
    redirect: '/dashboard/index',
    meta: {
      title: '首页',
      icon: 'home',
      noCache: true
    },
    children: [
      {
        path: 'index',
        name: 'dashboard-index',
        component: _import('dashboard/index')
      }
    ]
  },
  {
    path: '/components',
    component: Layout,
    redirect: 'noredirect',
    name: 'components',
    meta: {
      title: '组件',
      icon: 'dashboard'
    },
    children: [
      {
        path: 'tinymce',
        name: 'components-tinymce',
        component: _import('components/components_tinymce/index'),
        meta: {
          title: '富文本编辑器',
          icon: 'format_color_text'
        }
      },
      {
        path: 'dndList',
        name: 'components-dndList',
        component: _import('components/components_dndList/index'),
        meta: {
          title: '列表拖拽',
          icon: 'playlist_play'
        }
      },
      {
        path: 'avatarUpload',
        name: 'components-avatarUpload',
        component: _import('components/components_avatarUpload/index'),
        meta: {
          title: '头像上传',
          icon: 'add_a_photo'
        }
      }
    ]
  },
  {
    path: '/echarts',
    component: Layout,
    redirect: '/echarts/keyboard',
    name: 'echarts',
    meta: {
      title: '图表',
      icon: 'camera'
    },
    children: [
      {
        path: 'line',
        name: 'echarts-line',
        component: _import('echarts/echarts_line/index'),
        meta: {
          title: '折线图',
          icon: 'broken_image'
        }
      },
      {
        path: 'keyboard',
        name: 'echarts-keyboard',
        component: _import('echarts/echarts_keyboard/index'),
        meta: {
          title: '键盘图表',
          icon: 'equalizer'
        }
      },

      {
        path: 'mixchart',
        name: 'echarts-mixchart',
        component: _import('echarts/echarts_mixchart/index'),
        meta: {
          title: '混合图表',
          icon: 'timeline'
        }
      }
    ]
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/tab-table',
    meta: {
      title: '综合实例',
      icon: 'donut_large'
    },
    children: [
      {
        path: 'tab-table',
        name: 'tab-table',
        component: _import('example/tab_table/index'),
        meta: {
          title: 'tab表格',
          icon: 'view_column'
        }
      },
      {
        path: 'active-table',
        name: 'active-table',
        component: _import('example/active_table/index'),
        meta: {
          title: '动态表格',
          icon: 'donut_small'
        }
      },
      {
        path: 'drop-table',
        name: 'drop-table',
        component: _import('example/drop_table/index'),
        meta: {
          title: '拖拽表格',
          icon: 'slow_motion_video'
        }
      },
      {
        path: 'edit-table',
        name: 'edit-table',
        component: _import('example/edit_table/index'),
        meta: {
          title: '表格内编辑',
          icon: 'edit'
        }
      }
    ]
  },
  {
    path: '/error',
    component: Layout,
    redirect: '/error/404',
    name: 'error',
    meta: {
      title: '错误页面',
      icon: 'block'
    },
    children: [
      {
        path: '401',
        name: 'error-401',
        component: _import('error/401/index'),
        meta: {
          title: '401',
          icon: 'highlight_off'
        }
      },
      {
        path: '404',
        name: 'error-404',
        component: _import('error/404/index'),
        meta: {
          title: '404',
          icon: 'help_outline'
        }
      }
    ]
  },
  {
    path: '/excel',
    name: 'excel',
    component: Layout,
    redirect: '/excel/export',
    meta: {
      title: 'excel',
      icon: 'explicit'
    },
    children: [
      {
        path: 'export',
        name: 'excel-export',
        component: _import('excel/excel_export/index'),
        meta: {
          title: '导出excel',
          icon: 'get_app'
        }
      },
      {
        path: 'upload',
        name: 'excel-upload',
        component: _import('excel/excel_upload/index'),
        meta: {
          title: '导入excel',
          icon: 'cloud_upload'
        }
      }
    ]
  }
]

//实例化vue的时候只挂载constantRouter
export default new Router({
  routes: constantRouterMap
})

/** 需要超管权限的路由表 登录后根据roles决定是否添加 该路由表 **/

export const asyncRouterMap = [
  {
    path: '/permission',
    name: 'permission',
    component: Layout,
    redirect: '/permission/index',
    meta: { title: '权限测试', icon: 'lock_outline', roles: ['admin'] },
    children: [
      {
        path: 'index',
        name: 'permission-index',
        component: _import('permission/index')
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
